﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;
using System.Collections.Generic;
namespace TuyenDungViecLam.User_control
{
    public partial class Menu_Search : System.Web.UI.UserControl
    {
        struct NgayDang
        {
            int _snd;

            public int Snd
            {
                get { return _snd; }
                set { _snd = value; }
            }
            string _ten;

            public string Ten
            {
                get { return _ten; }
                set { _ten = value; }
            }
        }
        protected void rpcapbac_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            if (e.CommandName == "CapBac")
            {
                string temp1 = "Mcb";
                string temp2 = "&Mcb=";
                ChangeURL(e, ref urlnew, ref urlprevious, temp1, temp2);
            }
            Response.Redirect(urlnew);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rpdiadiem.DataSource = ChiTietCongViec_BUS.DanhSachNoiLamViec();
                rpdiadiem.DataBind();

                rpnghenghiep.DataSource = NganhNghe_BUS.DanhSachCacNganhNghe();
                rpnghenghiep.DataBind();

                List<NgayDang> dsngaydang = new List<NgayDang>();
                NgayDang nd = new NgayDang();
                nd.Ten = "Tất cả các ngày";
                nd.Snd = 0;
                dsngaydang.Add(nd);
                for (int i = 1; i <= 15; i++)
                {
                    nd = new NgayDang();
                    nd.Ten = "Trong vòng " + i + " ngày";
                    nd.Snd = i;
                    dsngaydang.Add(nd);
                }
                nd.Ten = "Trong vòng " + 30 + " ngày";
                nd.Snd = 30;
                dsngaydang.Add(nd);

                rpngaydang.DataSource = dsngaydang;
                rpngaydang.DataBind();

                rpcapbac.DataSource = ChiTietCongViec_BUS.DanhSachCacCapBac();
                rpcapbac.DataBind();

                rploaihinhcongviec.DataSource = ChiTietCongViec_BUS.DanhSachCacLoaiHinhCongViec();
                rploaihinhcongviec.DataBind();
            }
        }


        protected void rpdiadiem_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            if (e.CommandName == "NoiLamViec")
            {
                string temp1 = "Mnlv";
                string temp2 = "&Mnlv=";
                ChangeURL(e, ref urlnew, ref urlprevious, temp1, temp2);
            }
            Response.Redirect(urlnew);
        }

        private void ChangeURL(RepeaterCommandEventArgs e, ref string urlnew, ref string urlprevious, string temp1, string temp2)
        {
            string querynew = temp2 + e.CommandArgument.ToString();
            if (urlprevious.Contains(temp2))
            {
                string queryold = temp2 + Request.QueryString[temp1];
                urlprevious = urlprevious.Replace(queryold, querynew);
                urlnew = urlprevious;
            }
            else
            {
                urlprevious += querynew;
                urlnew = urlprevious;
            }
        }



        protected void rpnghenghiep_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            if (e.CommandName == "NganhNghe")
            {
                string temp1 = "Mng";
                string temp2 = "&Mng=";
                ChangeURL(e, ref urlnew, ref urlprevious, temp1, temp2);
            }
            Response.Redirect(urlnew);
        }

        protected void rploaihinhcongviec_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            if (e.CommandName == "LoaiHinhCongViec")
            {
                string temp1 = "Mlhcv";
                string temp2 = "&Mlhcv=";
                ChangeURL(e, ref urlnew, ref urlprevious, temp1, temp2);
            }
            Response.Redirect(urlnew);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            string querynew = "&Snkn=" + tbsonamkinhnghiem.Text;
            if (urlprevious.Contains("&Snkn="))
            {
                string queryold = "&Snkn=" + Request.QueryString["Snkn"];
                urlprevious = urlprevious.Replace(queryold, querynew);
                urlnew = urlprevious;
            }
            else
            {
                urlprevious += querynew;
                urlnew = urlprevious;
            }
            Response.Redirect(urlnew);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            string querynew = "&Lmin=" + tbluongmin.Text + "&Lmax=" + tbluongmax.Text;
            if (urlprevious.Contains("&Lmin="))
            {
                string queryold = "&Lmin=" + Request.QueryString["Lmin"] + "&Lmax=" + Request.QueryString["Lmax"];
                urlprevious = urlprevious.Replace(queryold, querynew);
                urlnew = urlprevious;
            }
            else
            {
                urlprevious += querynew;
                urlnew = urlprevious;
            }
            Response.Redirect(urlnew);
        }

        protected void rpngaydang_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string urlnew = "";
            string urlprevious = Request.Url.AbsoluteUri;
            if (e.CommandName == "NgayDang")
            {
                string temp1 = "Snd";
                string temp2 = "&Snd=";
                ChangeURL(e, ref urlnew, ref urlprevious, temp1, temp2);
            }
            Response.Redirect(urlnew);
        }

    }
}